<template>
  <div class="hospital-work-box">
    <div class="title">
      <span class="title-name">{{
        workData.baseMap ? workData.baseMap.hosname : ""
      }}</span>
      <span class="title-department">{{
        workData.baseMap ? workData.baseMap.bigname : ""
      }}</span>
      <span class="point">.</span>
      <span>{{ workData.baseMap ? workData.baseMap.depname : "" }}</span>
    </div>
    <div class="timer">
      <div class="timer-data">
        {{ workData.baseMap ? workData.baseMap.workDateString : "" }}
      </div>
      <ul class="timer-list">
        <li
          v-for="item in workData.bookingScheduleList"
          :key="item"
          @click="changeCur(item)"
          :class="{
            active: item.status == -1 || item.availableNumber == -1,
            cur: item.workDate == workTime.workDate,
          }"
        >
          <div class="li-time">{{ item.workDate }}-{{ item.dayOfWeek }}</div>
          <div class="li-num" v-if="item.status == -1">停止挂号</div>
          <div class="li-num" v-if="item.status == 0">
            {{
              item.availableNumber == -1
                ? `约满了`
                : `有号(${item.availableNumber})`
            }}
          </div>
          <div class="li-num" v-if="item.status == 1">即将放号</div>
        </li>
      </ul>
    </div>
    <el-pagination
      layout="prev, pager, next"
      :total="total"
      v-model:current-page="page"
      @current-change="getHospitalWork"
    />
    <!-- 即将放号 -->
    <!-- 已有号源 -->
    <div>
      <div
        v-if="workTime.status == 1"
        style="
          color: aquamarine;
          font-size: 20px;
          font-weight: 900;
          text-align: center;
        "
      >
        <span>2023年{{ workTime.workDateMd }}</span>
        <span>放号</span>
      </div>
      <div class="num-allocation-box" v-else>
        <div class="morning-box">
          <el-icon color="yellow" size="35px"><Sunny /></el-icon>
          <div class="morning-num">上午号源</div>
        </div>
        <ul class="doc-box">
          <li v-for="item in morArr" :key="item.id">
            <div class="lef-box">
              <span>{{ item.title }}</span>
              <span>|</span>
              <span>{{ item.docname }}</span>
              <div class="dep-bin">{{ item.skill }}</div>
            </div>
            <div class="rig-box">
              <span class="dep-money">￥100元</span>
              <el-button type="primary" @click="goRegPosition(item.id)">{{
                item.availableNumber
              }}</el-button>
            </div>
          </li>
        </ul>
        <div class="afternoon-box">
          <el-icon color="blue" size="35px"><MoonNight /></el-icon>
          <div class="afternoon-num">下午号源</div>
        </div>
        <ul class="doc-box">
          <li v-for="item in aftArr" :key="item.id">
            <div class="lef-box">
              <span>{{ item.title }}</span>
              <span>|</span>
              <span>{{ item.docname }}</span>
              <div class="dep-bin">{{ item.skill }}</div>
            </div>
            <div class="rig-box">
              <span class="dep-money">￥100元</span>
              <el-button type="primary" @click="goRegPosition(item.id)">{{
                item.availableNumber
              }}</el-button>
            </div>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import { reqHospitalWork, reqHospitalDoctor } from "@/api/HospitalPage";
export default {
  name: "register_step1",
  data() {
    return {
      page: 1,
      limit: 6,
      hosode: this.$route.query.hoscode,
      depcode: this.$route.query.depcode,
      workData: {},
      workTime: {},
      total: 0,
      dorArr: [],
    };
  },
  methods: {
    async getHospitalWork() {
      let result = await reqHospitalWork(
        this.page,
        this.limit,
        this.hosode,
        this.depcode
      );
      if (result.code == 200) {
        this.workData = result.data;
        this.workTime = result.data.bookingScheduleList[0];
        this.total = result.data.total;
        this.getHospitalDoctor();
      }
    },
    changeCur(item) {
      this.workTime = item;
      this.getHospitalDoctor();
    },
    async getHospitalDoctor() {
      let result = await reqHospitalDoctor(
        this.hosode,
        this.depcode,
        this.workTime.workDate
      );
      if (result.code == 200) {
        this.dorArr = result.data;
      }
    },
    goRegPosition(docId) {
      this.$router.push({
        path: "/hospital/register_step2",
        query: { docId: docId },
      });
    },
  },
  computed: {
    morArr() {
      return this.dorArr.filter((item) => item.workTime == 0);
    },
    aftArr() {
      return this.dorArr.filter((item) => item.workTime == 1);
    },
  },
  mounted() {
    this.getHospitalWork();
  },
};
</script>

<style lang="scss" scoped>
.hospital-work-box {
  .title {
    span {
      color: #7f7f7f;
    }
    .title-name {
      padding-right: 5px;
      border-right: 5px solid skyblue;
    }
    .title-department {
      padding-left: 5px;
    }
    .point {
      font-size: 20px;
      color: skyblue;
      padding-right: 5px;
      padding-left: 5px;
    }
  }
  .timer {
    padding-top: 30px;
    .timer-data {
      font-weight: 700;
      text-align: center;
    }
    .timer-list {
      height: 102px;
      margin-top: 30px;
      margin-bottom: 30px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      li {
        cursor: pointer;
        width: 150px;
        height: 90px;
        border: 1px solid #e8f2ff;
        &.active {
          border: 1px solid #ccc;
          .li-time {
            background-color: #ccc;
            color: #7f7f7f;
          }
          .li-num {
            color: #7f7f7f;
          }
        }
        &.cur {
          /* 缩放1.1倍 */
          transform: scale(1.1);
        }
        .li-time {
          height: 30px;
          line-height: 30px;
          text-align: center;
          background-color: #e8f2ff;
        }
        .li-num {
          height: 60px;
          text-align: center;
          line-height: 60px;
        }
      }
    }
  }
  .el-pagination {
    display: flex;
    justify-content: center;
    margin-bottom: 30px;
  }
  .num-allocation-box {
    .morning-box {
      display: flex;
      align-items: center;
      margin-bottom: 10px;
      .morning-num {
        color: #7f7f7f;
        font-weight: 900;
        margin-left: 5px;
      }
    }
    .afternoon-box {
      margin-top: 20px;
      margin-bottom: 10px;
      display: flex;
      align-items: center;
      .afternoon-num {
        color: #7f7f7f;
        font-weight: 900;
        margin-left: 5px;
      }
    }
    .doc-box {
      li {
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-bottom: 1px solid #ccc;
        margin-bottom: 10px;
        .lef-box {
          color: #87ceeb;
          margin-top: 10px;
          span {
            margin: 0px 5px;
            font-size: 18px;
            font-weight: 900;
          }
          .dep-bin {
            margin: 10px 0px;
            color: #7f7f7f;
          }
        }
        .rig-box {
          .dep-money {
            color: #7f7f7f;
            font-weight: 900;
            margin-right: 30px;
          }
        }
      }
    }
  }
}
</style>
